package com.gorkr.meituan;



import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * @author gorkr
 * @date 2022/03/26 19:49
 **/


public class M002 {
    static TreeMap<Integer,Integer> map =  new TreeMap<Integer,Integer>();
    static TreeSet<Integer> bound = new TreeSet<>();  // 边界
    static int[] prefix = new int[50050];

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(br.readLine());
        String[] arr = br.readLine().split(" ");
        String[] query = br.readLine().split(" ");

        for (int i = 0; i < n; i++) {
            prefix[i+1] = prefix[i] + Integer.parseInt(arr[i]);
        }

        bound.add(0);
        bound.add(n+1);
        for (int i = 0; i < n; i++) {
            int pos = Integer.parseInt(query[i]);
            Integer left = bound.lower(pos); // 它返回比此TreeSet中的给定元素(pos)低的最高元素
            Integer right = bound.higher(pos);
            // 消除警告
            if (left == null || right == null) {
                continue;
            }
            int seg_sum = prefix[right-1] - prefix[left]; // 这个长度被拆分
            Integer cnt = map.get(seg_sum);
            if (cnt != null){
                if(cnt==1){
                    map.remove(seg_sum);
                }else {
                    map.put(seg_sum, cnt-1);
                }
            }
            int left_sum = prefix[pos -1] - prefix[left];
            int right_sum = prefix[right-1] - prefix[pos];
            bound.add(pos);
            map.put(left_sum, map.getOrDefault(left_sum, 0) + 1);
            map.put(right_sum, map.getOrDefault(right_sum, 0) + 1);
            bw.write(map.lastKey() + "\n");


        }
        bw.close();






    }

}
    